<template>
	<view class="fill-width-height pagecontent" :class="$thatThemeClassName">
		<web-view
			v-if="webViewUrl.length > 0"
			:src="webViewUrl"
			:webview-styles="webviewStyles"
			@error="error"
			@load="load"
		>
		</web-view>
		<uv-empty v-if="errorState" mode="page" icon="https://cdn.uviewui.com/uview/empty/car.png"></uv-empty>
	</view>
</template>

<script>
	import config from '@/config'
	export default {
		props: {
			viewUrl: ''
		},
		data() {
			return {
				webViewUrl: '',
				webviewStyles: {
					progress: {
						color: '#FF3333'
					}
				},
				errorState: false
			}
		},
		methods: {
			load(){
				
			},
			error(){
				this.errorState = true
			}
		},
		onLoad(params){
			const token = uni.getStorageSync("token");
			const decodeParams = decodeURIComponent(params.params)
			const extParams = JSON.parse(decodeParams)
			const webViewUrl = extParams?.webViewUrl || this.viewUrl
			const configObj = JSON.stringify(config)
			
			// 假设 configObj 是一个对象，我们需要将其转换为 JSON 字符串，并对所有参数进行 URL 编码
			const encodedImgUrl = encodeURIComponent(extParams.imgUrl);
			const encodedToken = encodeURIComponent(token);
			const encodedConfig = encodeURIComponent(configObj);
			
			// 构建最终的 URL
			this.webViewUrl = `${webViewUrl}?imgUrl=${encodedImgUrl}&token=${encodedToken}&config=${encodedConfig}`;
			// this.webViewUrl = `${webViewUrl}?imgUrl=${extParams.imgUrl}&token=${token}&config=${configObj}`
		}
	}
</script>

<style>

</style>
